<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>quickSort</title>
</head>
<body>

</body>
<script>
    //快速排序
    var arr = [1, 4, 6, 8, 2, 7, 20, 6, 88];
    function quickSort(arr) {
        if (arr.length <= 1) {
            return arr
        }
        var index = Math.floor(arr.length / 2);// index = 3
        var value = arr.splice(index, 1)[0];//7

        var left = [];//[1]      // [4,6,6]    //    left = [4,6] [6]

        var ringht = [];//[4,6,8,7,6,20,88]  //[8,20,88]  ///  [8]  [20] [88]

        for (var i = 0; i < arr.length; i++) {
            var cur = arr[i];//1
            cur < value ? left.push(cur) : ringht.push(cur);
        }

        return quickSort(left).concat([value], quickSort(ringht));
    }
    alert(quickSort(arr));
</script>
</html>